home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 14.3 KB | 762 lines | [TEXT/MPS ] |
- /*
- File: CRString.cp
-
- Contains: xxx put contents here xxx
-
- Written by: Tim Harnett
-
- Copyright: © 1992 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <4> 2/21/95 TMH metrowerks changes
- <3> 1/11/95 TMH placated the compiler with a void* cast
- <2> 10/13/94 TMH added CRecordType assigment operator
- <1> 9/20/94 TMH Abandon RoadsideRest embrace Mercury
- <10> 1/18/94 EMS Added FormBackwardNameMethod
- <9> 11/12/93 TMH fix CString256::Strip
- <8> 6/24/93 EMS Fixed Strip
- <7> 6/24/93 EMS Fixed strip bug
- <6> 6/22/93 EMS Added Strip
- <5> 1/14/93 TMH a14 upgrades
- <4> 10/29/92 TMH RStringHandle constructors
- <3> 10/29/92 TMH handle nil pointers in CRecordType constructors
- <2> 9/25/92 EMS refined #include'ing of .h files and moved classes, globals etc.
- <1> 9/8/92 TMH The Great Project Restructuring of 1992
- <4> 7/10/92 TMH CRString* constructor for CAttributeType
- <2+> 6/23/92 SMT adding default constructor for CRString
- <2> 6/23/92 TMH fixed bugs in CRecordName constructors and assignment operator.
- 5/28/92 TMH New with A8 upgrades
-
- To Do:
- */
-
- #ifndef __CRString__
- #include "CRString.h"
- #endif
-
- /*
- * CRString
- */
-
- #pragma segment CRString
-
- CRString::CRString()
- {
- fCharSet = kDefaultCharSet;
- fBodyLength = 0;
- }
-
- CRString::CRString(short charSet)
- {
- fCharSet = charSet;
- fBodyLength = 0;
- }
-
- //----------------------------------------------------------------------------------------------------
- void CRString::Strip( char theChar, Boolean /*stripAll*/, Boolean stripLeading, Boolean stripTrailing )
- {
- // We don't do strip All yet
-
- short sLen = fBodyLength;
- char* sPtr = (char*) fBody+(sLen-1); // point to last char in string
-
- // Strip trailing blanks
- while( stripTrailing && (sLen>0) && (*sPtr==theChar) ) {
- sPtr--;
- sLen--;
- }
-
-
- sPtr = (char*)fBody;
-
- // Strip Leading Spaces
- while( stripLeading && (sLen>0) && (*sPtr==theChar) ) {
- sPtr++;
- sLen--;
- }
-
-
- if( (sLen != fBodyLength) && (sPtr != (char*)fBody) )
- memcpy(fBody,sPtr,sLen);
-
-
- fBodyLength = sLen;
-
-
- }
-
-
-
- /*
- * CRString16
- */
-
-
- CRString16::CRString16(const char* str,short charSet)
- {
-
- fBodyLength = str == 0 ? 0 : strlen(str);
-
- fCharSet = charSet;
-
- if( fBodyLength > kRString16BodySize )
- fBodyLength = kRString16BodySize;
-
- memcpy(fBody,str,fBodyLength);
- }
-
- CRString16::CRString16(const RString* rstr)
- {
- if( rstr == 0 ) {
- fCharSet = 0;
- fBodyLength = 0;
-
- } else {
-
- fCharSet = rstr->charSet;
-
- fBodyLength = rstr->dataLength;
- if( fBodyLength > kRString16BodySize )
- fBodyLength = kRString16BodySize;
-
- memcpy(fBody,rstr->body,fBodyLength);
- }
- }
-
- CRString16::CRString16(const RStringHandle rstr)
- {
- if( rstr == 0 ) {
- fCharSet = 0;
- fBodyLength = 0;
-
- } else {
-
- fCharSet = (*rstr)->charSet;
-
- fBodyLength = (*rstr)->dataLength;
- if( fBodyLength > kRString16BodySize )
- fBodyLength = kRString16BodySize;
-
- memcpy(fBody,(*rstr)->body,fBodyLength);
- }
- }
-
- CRString16::CRString16(const CStr255& cstr255,short charSet)
- {
- fBodyLength = cstr255.Length();
- fCharSet = charSet;
-
- if( fBodyLength > kRString16BodySize )
- fBodyLength = kRString16BodySize;
-
- memcpy(fBody,&cstr255.fStr[1],fBodyLength);
-
- }
-
- //-------------------------
- // C R S t r i n g 3 2
- //----------------------------
-
-
-
- CRString32::CRString32(const char* str,short charSet)
- {
-
- fBodyLength = str == 0 ? 0 : strlen(str);
-
- fCharSet = charSet;
-
- if( fBodyLength > kRString32BodySize )
- fBodyLength = kRString32BodySize;
-
- memcpy(fBody,str,fBodyLength);
- }
-
- CRString32::CRString32(const RString* rstr)
- {
- if( rstr == 0 ) {
- fCharSet = 0;
- fBodyLength = 0;
-
- } else {
-
- fCharSet = rstr->charSet;
-
- fBodyLength = rstr->dataLength;
- if( fBodyLength > kRString32BodySize )
- fBodyLength = kRString32BodySize;
-
- memcpy(fBody,rstr->body,fBodyLength);
- }
- }
-
- CRString32::CRString32(const RStringHandle rstr)
- {
- if( rstr == 0 ) {
- fCharSet = 0;
- fBodyLength = 0;
-
- } else {
-
- fCharSet = (*rstr)->charSet;
-
- fBodyLength = (*rstr)->dataLength;
- if( fBodyLength > kRString32BodySize )
- fBodyLength = kRString32BodySize;
-
- memcpy(fBody,(*rstr)->body,fBodyLength);
- }
- }
-
- CRString32::CRString32(const CStr255& cstr255,short charSet)
- {
- fBodyLength = cstr255.Length();
- fCharSet = charSet;
-
- if( fBodyLength > kRString32BodySize )
- fBodyLength = kRString32BodySize;
-
- memcpy(fBody,&cstr255.fStr[1],fBodyLength);
-
- }
-
-
- /*
- * CRString256
- */
-
-
- CRString256::CRString256(const char* str,short charSet)
- {
-
- fBodyLength = str == 0 ? 0 : strlen(str);
-
- fCharSet = charSet;
-
- if( fBodyLength > kRString256BodySize )
- fBodyLength = kRString256BodySize;
-
- memcpy(fBody,str,fBodyLength);
- }
-
- CRString256::CRString256(const RString* rstr)
- {
- if( rstr == 0 ) {
- fCharSet = 0;
- fBodyLength = 0;
-
- } else {
-
- fCharSet = rstr->charSet;
-
- fBodyLength = rstr->dataLength;
- if( fBodyLength > kRString256BodySize )
- fBodyLength = kRString256BodySize;
-
- memcpy(fBody,rstr->body,fBodyLength);
- }
- }
- CRString256::CRString256(const RStringHandle rstr)
- {
- if( rstr == 0 ) {
- fCharSet = 0;
- fBodyLength = 0;
-
- } else {
-
- fCharSet = (*rstr)->charSet;
-
- fBodyLength = (*rstr)->dataLength;
- if( fBodyLength > kRString256BodySize )
- fBodyLength = kRString256BodySize;
-
- memcpy(fBody,(*rstr)->body,fBodyLength);
- }
- }
-
- CRString256::CRString256(const CStr255& cstr255,short charSet)
- {
- fBodyLength = cstr255.Length();
- fCharSet = charSet;
-
- if( fBodyLength > kRString256BodySize )
- fBodyLength = kRString256BodySize;
-
- memcpy(fBody,&cstr255.fStr[1],fBodyLength);
-
- }
-
- /*
- * CRecordName
- */
-
- CRecordName::CRecordName() : CRString() { fCharSet = kDefaultCharSet; }
- CRecordName::CRecordName(const char* str,short charSet)
- {
-
- fBodyLength = str == 0 ? 0 : strlen(str);
-
- fCharSet = charSet;
-
- if( fBodyLength > kRecordNameBodySize )
- fBodyLength = kRecordNameBodySize;
-
- memcpy(fBody,str,fBodyLength);
- }
-
-
- CRecordName::CRecordName(const RString* rstr)
- {
- if( rstr == 0 ) {
- fCharSet = 0;
- fBodyLength = 0;
-
- } else {
-
- fBodyLength = rstr->dataLength;
-
- if( fBodyLength > kRecordNameBodySize )
- fBodyLength = kRecordNameBodySize;
-
- fCharSet = rstr->charSet;
- BlockMove((Ptr)rstr->body,(Ptr) fBody,fBodyLength);
-
- }
-
- }
- CRecordName::CRecordName(const RStringHandle rstr)
- {
- if( rstr == 0 ) {
- fCharSet = 0;
- fBodyLength = 0;
-
- } else {
-
- fBodyLength = (*rstr)->dataLength;
-
- if( fBodyLength > kRecordNameBodySize )
- fBodyLength = kRecordNameBodySize;
-
- fCharSet = (*rstr)->charSet;
- BlockMove((Ptr)(*rstr)->body,(Ptr) fBody,fBodyLength);
-
- }
-
- }
-
-
- CRecordName::CRecordName(const CRString* crstr)
- {
- if( crstr == 0 ) {
- fCharSet = 0;
- fBodyLength = 0;
-
- } else {
-
- fBodyLength = crstr->fBodyLength;
-
- if( fBodyLength > kRecordNameBodySize )
- fBodyLength = kRecordNameBodySize;
-
- fCharSet = crstr->fCharSet;
- BlockMove((Ptr)crstr->fBody,(Ptr) fBody,fBodyLength);
-
- }
-
- }
-
- CRecordName::CRecordName(CRString16& rstr16)
- {
- memcpy(this,rstr16,rstr16.Length());
- fCharSet = kDefaultCharSet;
- }
-
- CRecordName::CRecordName(const CStr255& cstr255,short charSet)
- {
- fBodyLength = cstr255.Length();
- fCharSet = charSet;
-
- if( fBodyLength > kRecordNameBodySize )
- fBodyLength = kRecordNameBodySize;
-
- memcpy(fBody,&cstr255.fStr[1],fBodyLength);
-
- }
-
- CRecordName& CRecordName::operator =(const RString* rstr)
- {
- if( rstr == 0 ) {
- fCharSet = 0;
- fBodyLength = 0;
-
- } else {
-
- fBodyLength = rstr->dataLength;
-
- if( fBodyLength > kRecordNameBodySize )
- fBodyLength = kRecordNameBodySize;
-
- fCharSet = rstr->charSet;
- BlockMove((Ptr)rstr->body,(Ptr) fBody,fBodyLength);
-
- }
-
- return *this;
-
- };
-
-
-
- //--------------------------------------------------------------------------------------
- Boolean CRecordName::FormBackwardString( CRecordName& out, Boolean failMultipleBreaks )
- {
- short splitChar = 32;
- short split = this->fBodyLength;
- Boolean formable = false;
-
- if ( this->CharSet() == smRoman ) {
-
- //-- strip off trailing spaces.
- while ( ( this->fBody[ split ] == 32 ) && split) split--;
-
- //-- find first space
- while ( ( this->fBody[ split ] != 32) && split ) split--;
-
- //-- If the orig string has more than one split then set split location to zero thereby blowing out.
- if ( failMultipleBreaks ) {
- short tempSpot = split;
- while ( ( this->fBody[ tempSpot ] != 32) && tempSpot ) tempSpot--;
- if ( tempSpot > 0 )
- split = 0;
- }
-
- if ( ( this->fBody[ split ] == 32 ) && split ) { //build the alias name
- formable = true;
-
- short lengthAfterSpace = this->fBodyLength - split - 1;
- short lengthBeforeSpace = split;
-
- BlockMove(&this->fBody[ split + 1 ], &out.fBody[0], lengthAfterSpace);
-
- out.fBody[lengthAfterSpace] = ',';
-
- if ( this->fBodyLength < 63 ) {
- out.fBody[lengthAfterSpace + 1] = 32;
- BlockMove(&this->fBody[0], &out.fBody[lengthAfterSpace+2], lengthBeforeSpace );
- out.fBodyLength = this->fBodyLength + 1;
- } else {
- BlockMove(&this->fBody[0], &out.fBody[lengthAfterSpace+1], lengthBeforeSpace );
- out.fBodyLength = this->fBodyLength;
- }
-
- } else { //alias name is same as inputName
-
- BlockMove(&this->fBody[0], &out.fBody[0], this->fBodyLength);
- out.fBodyLength = this->fBodyLength;
- }
- out.fCharSet = this->fCharSet;
- }
-
- return formable;
- };
-
-
-
-
-
- /*
- * CDirectoryName
- */
-
-
- CDirectoryName::CDirectoryName(const char* str,short charSet)
- {
-
- fBodyLength = str == 0 ? 0 : strlen(str);
-
- fCharSet = charSet;
-
- if( fBodyLength > kDirectoryNameBodySize )
- fBodyLength = kDirectoryNameBodySize;
-
- memcpy(fBody,str,fBodyLength);
- }
-
- CDirectoryName::CDirectoryName(const RString* rstr)
- {
- fCharSet = rstr->charSet;
-
- fBodyLength = rstr->dataLength;
- if( fBodyLength > kDirectoryNameBodySize )
- fBodyLength = kDirectoryNameBodySize;
-
- memcpy(fBody,rstr->body,fBodyLength);
- }
-
- CDirectoryName::CDirectoryName(const CStr255& cstr255,short charSet)
- {
- fBodyLength = cstr255.Length();
- fCharSet = charSet;
-
- if( fBodyLength > kDirectoryNameBodySize )
- fBodyLength = kDirectoryNameBodySize;
-
- memcpy(fBody,&cstr255.fStr[1],fBodyLength);
-
- }
-
- /*
- * CNetworkName
- */
-
-
- CNetworkName::CNetworkName(const char* str,short charSet)
- {
-
- fBodyLength = str == 0 ? 0 : strlen(str);
-
- fCharSet = charSet;
-
- if( fBodyLength > kNetworkNameBodySize )
- fBodyLength = kNetworkNameBodySize;
-
- memcpy(fBody,str,fBodyLength);
- }
-
- CNetworkName::CNetworkName(const RString* rstr)
- {
- fCharSet = rstr->charSet;
-
- fBodyLength = rstr->dataLength;
- if( fBodyLength > kNetworkNameBodySize )
- fBodyLength = kNetworkNameBodySize;
-
- memcpy(fBody,rstr->body,fBodyLength);
- }
-
- CNetworkName::CNetworkName(const CRString* crstr)
- {
- fBodyLength = crstr->BodyLength();
-
- if( fBodyLength > kNetworkNameBodySize )
- fBodyLength = kNetworkNameBodySize;
-
- memcpy(this,crstr,sizeof(ProtoRString)+fBodyLength);
- }
-
- CNetworkName::CNetworkName(const CStr255& cstr255,short charSet)
- {
- fBodyLength = cstr255.Length();
- fCharSet = charSet;
-
- if( fBodyLength > kNetworkNameBodySize )
- fBodyLength = kNetworkNameBodySize;
-
- memcpy(fBody,&cstr255.fStr[1],fBodyLength);
-
- }
-
-
- /*
- * CRecordType
- */
-
-
- CRecordType::CRecordType(const char* str,short charSet)
- {
-
- fBodyLength = str == 0 ? 0 : strlen(str);
-
- fCharSet = charSet;
-
- if( fBodyLength > kRecordTypeBodySize )
- fBodyLength = kRecordTypeBodySize;
-
- memcpy(fBody,str,fBodyLength);
- }
-
- CRecordType::CRecordType(const RString* rstr)
- {
- if( rstr == 0 ) {
-
- fCharSet = kDefaultCharSet;
- fBodyLength = 0;
-
- } else {
-
- fCharSet = rstr->charSet;
-
- fBodyLength = rstr->dataLength;
- if( fBodyLength > kRecordTypeBodySize )
- fBodyLength = kRecordTypeBodySize;
-
- memcpy(fBody,rstr->body,fBodyLength);
- }
- }
- CRecordType::CRecordType(const RStringHandle rstr)
- {
- if( rstr == 0 ) {
-
- fCharSet = kDefaultCharSet;
- fBodyLength = 0;
-
- } else {
-
- fCharSet = (*rstr)->charSet;
-
- fBodyLength = (*rstr)->dataLength;
- if( fBodyLength > kRecordTypeBodySize )
- fBodyLength = kRecordTypeBodySize;
-
- memcpy(fBody,(*rstr)->body,fBodyLength);
- }
- }
-
- CRecordType::CRecordType(const CRString* crstr)
- {
- if( crstr == 0 ) {
-
- fCharSet = kDefaultCharSet;
- fBodyLength = 0;
-
- } else {
-
- fBodyLength = crstr->BodyLength();
-
- if( fBodyLength > kRecordTypeBodySize )
- fBodyLength = kRecordTypeBodySize;
-
- memcpy(this,crstr,sizeof(ProtoRString)+fBodyLength);
- }
-
- }
-
- CRecordType::CRecordType(const CStr255& cstr255,short charSet)
- {
- fBodyLength = cstr255.Length();
- fCharSet = charSet;
-
- if( fBodyLength > kRecordTypeBodySize )
- fBodyLength = kRecordTypeBodySize;
-
- memcpy(fBody,&cstr255.fStr[1],fBodyLength);
-
- }
-
- CRecordType& CRecordType::operator =(const RString* rstr)
- {
- if( rstr == 0 ) {
- fCharSet = 0;
- fBodyLength = 0;
-
- } else {
-
- fBodyLength = rstr->dataLength;
-
- if( fBodyLength > kRecordTypeBodySize )
- fBodyLength = kRecordTypeBodySize;
-
- fCharSet = rstr->charSet;
- BlockMove((Ptr)rstr->body,(Ptr) fBody,fBodyLength);
-
- }
-
- return *this;
-
- };
-
-
- /*
- * CAttributeType
- */
-
-
- CAttributeType::CAttributeType(const char* str,short charSet)
- {
-
- fBodyLength = str == 0 ? 0 : strlen(str);
-
- fCharSet = charSet;
-
- if( fBodyLength > kAttributeTypeBodySize )
- fBodyLength = kAttributeTypeBodySize;
-
- memcpy(fBody,str,fBodyLength);
- }
-
- CAttributeType::CAttributeType(const RString* rstr)
- {
-
- if( rstr == 0 ) {
- fCharSet = 0;
- fBodyLength = 0;
-
- } else {
-
- fBodyLength = rstr->dataLength;
-
- if( fBodyLength > kAttributeTypeBodySize )
- fBodyLength = kAttributeTypeBodySize;
-
- fCharSet = rstr->charSet;
- BlockMove((Ptr)rstr->body,(Ptr) fBody,fBodyLength);
-
- }
-
- }
- CAttributeType::CAttributeType(const RStringHandle rstr)
- {
-
- if( rstr == 0 ) {
- fCharSet = 0;
- fBodyLength = 0;
-
- } else {
-
- fBodyLength = (*rstr)->dataLength;
-
- if( fBodyLength > kAttributeTypeBodySize )
- fBodyLength = kAttributeTypeBodySize;
-
- fCharSet = (*rstr)->charSet;
- BlockMove((Ptr)(*rstr)->body,(Ptr) fBody,fBodyLength);
-
- }
-
- }
-
-
- CAttributeType::CAttributeType(const CRString* crstr)
- {
- if( crstr == 0 ) {
- fCharSet = 0;
- fBodyLength = 0;
-
- } else {
-
- fBodyLength = crstr->fBodyLength;
-
- if( fBodyLength > kAttributeTypeBodySize )
- fBodyLength = kAttributeTypeBodySize;
-
- fCharSet = crstr->fCharSet;
- BlockMove((Ptr)crstr->fBody,(Ptr) fBody,fBodyLength);
-
- }
-
- }
-
-
- CAttributeType::CAttributeType(const CStr255& cstr255,short charSet)
- {
- fBodyLength = cstr255.Length();
- fCharSet = charSet;
-
- if( fBodyLength > kAttributeTypeBodySize )
- fBodyLength = kAttributeTypeBodySize;
-
- memcpy(fBody,&cstr255.fStr[1],fBodyLength);
-
- }
-